<template>
  <div class="cellpage systemPage-wrapper">
    <div class="topbar">
      <span class="iconfont iconxitongpingtai-yewumoxing titleIcon"></span>
      <span>业务模型</span>
    </div>
    <div class="content-background divcontent">
      <pageMenu
        :menuitems="menuitems"
        @itemclick="itemclick"
        @add="add"
        :activeitem="activeitem"
        :dropmenus="dropmenus"
        @dropitemclick="dropitemclick"
        @search="searchworkplanclass"
      ></pageMenu>
      <div class="page-cell-edit">
        <sysBussinessEdit :cellid="cellid" ref="bussiness"></sysBussinessEdit>
      </div>
    </div>

    <winAdd
      v-if="showWind"
      @close="closeWind"
      @ok="save"
      :title="addtitle"
      :activeItem="repClass"
    ></winAdd>
  </div>
</template>

<script>
import pageMenu from "../components/pageMenu.vue";
import sysBussinessEdit from "../components/sysBussinessEdit.vue";
import winAdd from "../components/winAdd.vue";
import {
  workplanclassquery,
  workplanclasssave,
  workplanclassdetail,
  workplanclassdelete,
} from "@/system/api/bussinessEdit";
export default {
  name: "bussinessEdit",
  components: {
    pageMenu,
    sysBussinessEdit,
    winAdd,
  },
  provide() {
    return {
      cEdit: this,
    };
  },
  data() {
    return {
      workplanclassParams: {
        name: "",
        pageIndex: 0,
        pageSize: 0,
      },
      menuitems: [],
      activeitem: 0,
      showWind: false,
      repClass: null,
      report: null,
      dropmenus: [
        {
          name: "编辑",
          iconPosition: "before",
          iconname: "editicon",
          value: 1,
        },
        {
          name: "删除",
          iconPosition: "before",
          iconname: "delicon",
          value: 2,
        },
      ],
      cellid: null,
      addtitle: null,
    };
  },
  mounted() {
    this.workplanclassquery();
  },
  methods: {
    itemclick(e, index) {
      this.activeitem = index;
      this.cellid = e.id;
      this.$refs.bussiness.setBussinessId(e.id);
    },
    add() {
      //				this.message('new',1);
      this.repClass = null;
      this.showWind = true;
      this.addtitle = "新增业务模型";
      this.activeitem = -1;
    },
    dropitemclick(item, dropItem, index) {
      //左侧菜单 编辑 删除 操作
      if (dropItem.name == "编辑") {
        this.addtitle = "编辑业务模型";
        this.repClass = item;
        let $state = item.state ? 1 : 0;
        this.$set(this.repClass, "state", $state);
        this.showWind = true;
      }
      if (dropItem.name == "删除") {
        let param = { id: item.id };
        workplanclassdelete(param).then((res) => {
          if (res.success) {
            this.activeitem = 0;
            this.workplanclassquery();
            this.message(res.msg, 1);
          } else {
            this.message(res.msg, 3);
          }
        });
      }
    },
    searchworkplanclass(e) {
      //搜索 workplanclass  信息
      this.workplanclassParams.name = e;
      this.workplanclassquery();
    },
    closeWind() {
      // 关闭 workplanclass 新增 编辑窗口
      this.showWind = false;
    },
    save(resinfo) {
      //保存 业务模型 class  信息
      this.showWind = false;
      this.repClass = resinfo;
      let $state = this.repClass.state == 1 ? true : false;
      this.$set(this.repClass, "state", $state);
      workplanclasssave(this.repClass).then((res) => {
        if (res.success) {
          workplanclassquery(this.workplanclassParams).then((resq) => {
            if (resq.success) {
              this.menuitems = resq.info;
              this.activeitem = this.getIndex(res.info.value);
              this.flowClassId = res.info.value;
              this.workflowdetail();
              this.workflowversion();
            } else {
              this.message(res.msg, 3);
            }
          });
        } else {
          this.message(res.msg, 3);
        }
      });
    },
    workplanclassquery() {
      workplanclassquery(this.workplanclassParams).then((res) => {
        if (res.success) {
          this.menuitems = res.info;
          this.$refs.bussiness.setBussinessId(this.menuitems[0].id);
          this.activeitem = 0;
        }
      });
    },
    getIndex(id) {
      let ind = 0;
      this.menuitems.forEach((item, index) => {
        if (item.id == id) {
          ind = index;
        }
      });
      return ind;
    },
  },
};
</script>

<style scoped>
.cellpage {
  width: 100%;
  height: calc(100% - 55px);
}

.titleIcon {
  font-size: 24px;
  margin: 0px 14px 0px 20px;
  color: rgba(83, 168, 255, 1);
}

.title {
  width: 72px;
  height: 19px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(0, 0, 0, 1);
  line-height: 21px;
  margin: 19px 0 18px 0px;
}
.divcontent {
  display: flex;
}
.page-cell-edit {
  margin-left: 12px;
  width: calc(100% - 246px);
  max-width: calc(100% - 246px);
  border-radius: 6px;
}
.page-cell ::-webkit-scrollbar {
  height: 3px;
  width: 3px;
}
</style>